package longrise.phone.com.bjjt_henan.Adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;

import longrise.phone.com.bjjt_henan.R;

public class SuggestAdapter extends BaseAdapter {

    private EntityBean[] dataLists;

    private Context context;

    public SuggestAdapter(Context context) {
        this.context = context;
    }

    public void setDataLists(EntityBean[] dataLists) {
        this.dataLists = dataLists;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (dataLists != null) {
            return dataLists.length;
        }
        return 0;
    }

    @Override
    public Object getItem(int arg0) {
        return arg0;
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_suggest_item, null);
            viewHolder.sugTV = (TextView) convertView.findViewById(R.id.suggest_item_sug);
            viewHolder.ctimeTV = (TextView) convertView.findViewById(R.id.suggest_item_ctime);
            viewHolder.ansTV = (TextView) convertView.findViewById(R.id.suggest_item_ans);
            viewHolder.timeTV = (TextView) convertView.findViewById(R.id.suggest_item_time);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        EntityBean data = dataLists[position];
        viewHolder.sugTV.setText(data.getString("suggestion"));
        viewHolder.ctimeTV.setText(data.getString("createtime"));
        String answer = data.getString("answer");
        if (TextUtils.isEmpty(answer)) {
            viewHolder.timeTV.setVisibility(View.GONE);
            viewHolder.ansTV.setVisibility(View.GONE);
        } else {
            viewHolder.timeTV.setVisibility(View.VISIBLE);
            viewHolder.ansTV.setVisibility(View.VISIBLE);
            viewHolder.ansTV.setText(answer);
            viewHolder.timeTV.setText(data.getString("answertime"));
        }
        return convertView;
    }

    private class ViewHolder {
        private TextView sugTV;
        private TextView ctimeTV;
        private TextView ansTV;
        private TextView timeTV;
    }
}
